/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MainPackage;


import java.util.Map;
import java.util.HashMap;

import org.jgrapht.*;
import org.jgrapht.graph.*;

/**
 * 
 * @author Santosh
 */

public class MainClass {

	public static void main(String[] args) throws Exception {
		try {
			System.out.println("MainClass: Starting program..");
			long startTime = System.currentTimeMillis();

			// Get a Graph class Handle.
			GraphM graphManip = new GraphM();
			FileM FileManip = new FileM();
			
			// Count the tags in each node.
			// This is only for data statistics.
			// FileManip.countTags(Settings.NODEDATAFILE);
			
			// Get the edges of nodes.
			// graphManip.getEdgesOfNodes();
			
			UndirectedGraph<String, DefaultEdge> stringGraph = graphManip
					.createStringGraph();

			// Read all features and store them.
			String[] nodeMeta = FileManip.getNodeMeta(Settings.NODEDATAMETA);
			
			// Generate Node data file with nodes that are only
			// in train data.
			
			// FileManip.generateNodeDataFromEdges(Settings.TRAINFILE);
			
			// Get a data set with all records in below format.
			// Map<String, Map<String, Integer>> vectorMap = new HashMap<String, Map<String, Integer>>();
			// vectorMap = FileManip.getFeatureVector(stringGraph, Settings.NODEDATAFILE,
			//		nodeMeta);
			
			// Print the vector map for debugging.
			// FileManip.printVectorMap(vectorMap, nodeMeta);

			// Get tags and counts of all neighbors.
			// Place them in a new vector map.

			// Map<String, Map<String, Integer>> neighborVectorMap = graphManip
			//		.getTagsOfNeighborNodes(stringGraph, vectorMap);

			// graphManip.generateOutputFile(vectorMap, nodeMeta);

			// Do cosine similarity for all these feature vectors.
			// Identify a threshold. If nodes have more similarity,
			// add an edge between the nodes (which means we predicted
			// a missing or future possible link).
			
			// Instead of doing this, we can simply use a simple matching
			// coefficient to mark a tag as 1 if both vectors have the
			// tag otherwise 0. If the SMC is greater than some threshold
			// mark a link.
			
			Map<String, Map<String, Short>> trainVectorMap = new HashMap<String, Map<String, Short>>();
			trainVectorMap = FileManip.getTrainVectors(Settings.NEIGBORNODEDATA,
					nodeMeta);
			
			graphManip.predictLinks(stringGraph, trainVectorMap, nodeMeta, Settings.TESTFILE);

			long endTime   = System.currentTimeMillis();
			long totalTime = endTime - startTime;
			System.out.println("Total run time: "+ (totalTime/1000) +"s");
			System.out.println("Program completed succesfully.");

		} catch (Throwable ex) {
			System.err.println("Uncaught exception - " + ex.getMessage());
			ex.printStackTrace(System.err);
		}
	}

}
